API Documentation
Public Member Functions | List of all members
nkMaths::Quaternion Class Reference

A quaternion, symbolizing rotations as a 4D vector. More...

Inheritance diagram for nkMaths::Quaternion:
nkMaths::Vector

Public Member Functions

 Quaternion ()
 
 Quaternion (float x, float y, float z, float w)
 
 Quaternion (const Vector &axis, float angle)
 
 Quaternion (const Vector &eulerAngles)
 
 Quaternion (const Matrix &mat)
 
 Quaternion (const Quaternion &other)
 
 ~Quaternion ()
 
Vector getAsEulerAngles () const
 
void setFromAxisAngle (const Vector &axis, float angle)
 
void setFromEuler (const Vector &angles)
 
void setFromMatrix (const Matrix &mat)
 
Vector transform (const Vector &vector) const
 
Quaternionoperator= (const Quaternion &other)
 
Quaternion operator* (const Quaternion &other) const
 
void operator*= (const Quaternion &other)
 
- Public Member Functions inherited from nkMaths::Vector
 Vector ()
 
 Vector (float x, float y)
 
 Vector (float x, float y, float z)
 
 Vector (float x, float y, float z, float w)
 
 Vector (const Vector &other)
 
 Vector (const IntVector &other)
 
 ~Vector ()
 
float getX () const
 
float getY () const
 
float getZ () const
 
float getW () const
 
void setX (float value)
 
void setY (float value)
 
void setZ (float value)
 
void setW (float value)
 
void addX (float value)
 
void addY (float value)
 
void addZ (float value)
 
void addW (float value)
 
void multX (float value)
 
void multY (float value)
 
void multZ (float value)
 
void multW (float value)
 
float getLengthVec2 () const
 
float getLengthVec3 () const
 
float getLengthVec4 () const
 
float getLengthSquaredVec2 () const
 
float getLengthSquaredVec3 () const
 
float getLengthSquaredVec4 () const
 
float getDistanceVec2 (const Vector &other) const
 
float getDistanceVec3 (const Vector &other) const
 
float getDistanceVec4 (const Vector &other) const
 
float getDistanceSquaredVec2 (const Vector &other) const
 
float getDistanceSquaredVec3 (const Vector &other) const
 
float getDistanceSquaredVec4 (const Vector &other) const
 
void normalizeVec2 ()
 
void normalizeVec3 ()
 
void normalizeVec4 ()
 
Vector getNormalizedVec2 () const
 
Vector getNormalizedVec3 () const
 
Vector getNormalizedVec4 () const
 
float dotProductVec2 (const Vector &other) const
 
float dotProductVec3 (const Vector &other) const
 
float dotProductVec4 (const Vector &other) const
 
void setAsCrossVec3 (const Vector &other)
 
Vector getCrossVec3 (const Vector &other) const
 
void fromString (const nkMemory::StringView &str)
 
Vectoroperator= (const Vector &other)
 
Vectoroperator= (const IntVector &other)
 
Vector operator+ (const Vector &other) const
 
void operator+= (const Vector &other)
 
Vector operator- (const Vector &other) const
 
void operator-= (const Vector &other)
 
Vector operator* (const Vector &other) const
 
void operator*= (const Vector &other)
 
Vector operator* (const Quaternion &other) const
 
void operator*= (const Quaternion &other)
 
Vector operator* (const Matrix &mat) const
 
void operator*= (const Matrix &other)
 
Vector operator* (float coeff) const
 
void operator*= (float coeff)
 
Vector operator/ (const Vector &other) const
 
void operator/= (const Vector &other)
 
Vector operator/ (float coeff) const
 
void operator/= (float coeff)
 
bool operator== (const Vector &other) const
 
bool operator!= (const Vector &other) const
 
bool operator< (const Vector &other) const
 
bool operator<= (const Vector &other) const
 
bool operator> (const Vector &other) const
 
bool operator>= (const Vector &other) const
 

Additional Inherited Members

- Static Public Member Functions inherited from nkMaths::Vector
static float distanceVec2 (const Vector &a, const Vector &b)
 
static float distanceVec3 (const Vector &a, const Vector &b)
 
static float distanceVec4 (const Vector &a, const Vector &b)
 
static float distanceSquaredVec2 (const Vector &a, const Vector &b)
 
static float distanceSquaredVec3 (const Vector &a, const Vector &b)
 
static float distanceSquaredVec4 (const Vector &a, const Vector &b)
 
static float dotVec2 (const Vector &a, const Vector &b)
 
static float dotVec3 (const Vector &a, const Vector &b)
 
static float dotVec4 (const Vector &a, const Vector &b)
 
static Vector crossVec3 (const Vector &a, const Vector &b)
 
- Public Attributes inherited from nkMaths::Vector
union {
   float   _x
 
   float   _r
 
   float   x
 
   float   r
 
}; 
 X or R component of the vector, accessible through different names.
 
union {
   float   _y
 
   float   _g
 
   float   y
 
   float   g
 
}; 
 Y or G component of the vector, accessible through different names.
 
union {
   float   _z
 
   float   _g
 
   float   z
 
   float   g
 
}; 
 Z or B component of the vector, accessible through different names.
 
union {
   float   _w
 
   float   _a
 
   float   w
 
   float   a
 
}; 
 W or A component of the vector, accessible through different names.
 

Detailed Description

A quaternion, symbolizing rotations as a 4D vector.

The equation for the quaternion is considered as : xi + yj + zk + w

Constructor & Destructor Documentation

◆ Quaternion() [1/6]

nkMaths::Quaternion::Quaternion ( )

Default constructor. Defaults to (0, 0, 0, 1), encoding no rotation.

◆ Quaternion() [2/6]

nkMaths::Quaternion::Quaternion ( float  x,
float  y,
float  z,
float  w 
)

Filling constructor.

Parameters
xThe x component.
yThe y component.
zThe z component.
wThe w component.

◆ Quaternion() [3/6]

nkMaths::Quaternion::Quaternion ( const Vector axis,
float  angle 
)

Axis angle constructor.

Parameters
axisThe axis of rotation to consider.
angleThe angle around this axis, in radians.

◆ Quaternion() [4/6]

nkMaths::Quaternion::Quaternion ( const Vector eulerAngles)

Euler angles constructor.

Parameters
eulerAnglesThe euler angles, considering rotation in ZYX (Yaw-Pitch-Roll) order.

◆ Quaternion() [5/6]

nkMaths::Quaternion::Quaternion ( const Matrix mat)

Matrix constructor.

Parameters
matThe matrix from which to extract the rotation.

◆ Quaternion() [6/6]

nkMaths::Quaternion::Quaternion ( const Quaternion other)

Copy constructor.

Parameters
otherThe quaternion to copy.

◆ ~Quaternion()

nkMaths::Quaternion::~Quaternion ( )

Destructor.

Member Function Documentation

◆ getAsEulerAngles()

Vector nkMaths::Quaternion::getAsEulerAngles ( ) const
Returns
The quaternion translated as euler angles, encoded with ZYX ordering (Yaw-Pitch-Roll).

◆ setFromAxisAngle()

void nkMaths::Quaternion::setFromAxisAngle ( const Vector axis,
float  angle 
)

Sets the quaternion from an axis and angle pair.

Parameters
axisThe axis to rotate around.
angleThe angle to rotate, in radians.

◆ setFromEuler()

void nkMaths::Quaternion::setFromEuler ( const Vector angles)

Sets the quaternion from euler angles.

Parameters
anglesThe euler angles to translate, considering rotation in ZYX (Yaw-Pitch-Roll) order.

◆ setFromMatrix()

void nkMaths::Quaternion::setFromMatrix ( const Matrix mat)

Sets the quaternion from a matrix.

Parameters
matThe matrix to extract the rotation from.

◆ transform()

Vector nkMaths::Quaternion::transform ( const Vector vector) const

Rotates a vector. Another way to express q * v.

Parameters
vectorThe vector to rotate.
Returns
The vector once rotated.

◆ operator=()

Quaternion& nkMaths::Quaternion::operator= ( const Quaternion other)

Assignment operator.

Parameters
otherThe quaternion to assign.

◆ operator*()

Quaternion nkMaths::Quaternion::operator* ( const Quaternion other) const

Multiplication operator.

Parameters
otherThe quaternion to multiply with.
Returns
A quaternion being the result of the multiplication of both quaternions.

◆ operator*=()

void nkMaths::Quaternion::operator*= ( const Quaternion other)

Multiplication and assignment operator.

Parameters
otherThe quaternion to multiply with.

The documentation for this class was generated from the following file: